package pzc.excel;

public class ExcelAssistant {

	public static final int colConvert(String colName){
		// from 1
		int colIndex = -1;
		if(colName.length() == 1){
			// A - Z
			colIndex = colName.charAt(0) - 64;
		}else{
			// AA - IV
			colIndex = (colName.charAt(0) - 64) * 26 + (colName.charAt(1) - 64);
		}
		
		System.out.println(colName + " -> " + colIndex);
		return colIndex;
	}

	public static final String colConvert(int colIndex){
		// from 1
		String colName = "";
		
		int n1 = (colIndex - (colIndex % 26)) / 26;
		int n2 = (colIndex % 26);
		
		if(n1 != 0){
			colName += String.valueOf((char)(n1 + 64));
		}
		if(n2 != 0){
			colName += String.valueOf((char)(n2 + 64));
		}

		System.out.println(colIndex + " -> " + colName);
		return colName;
	}
	
	public static void main(String[] args){
		colConvert("GQ");
		colConvert("BL");

		colConvert(64);
	}
}
